package so.shanku.essential.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.*;
import aym.util.getservicesdata.GetServicesDataQueue;
import aym.util.getservicesdata.GetServicesDataUtil;
import aym.util.json.JsonMap;
import aym.util.json.JsonParseHelper;
import aym.view.gridview.GridViewNoScroll;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import so.shanku.essential.R;
import so.shanku.essential.activity.ProductDetailActivity;
import so.shanku.essential.adapter.RelationProductAdapter;
import so.shanku.essential.adapter.SimpleBrandGridAdater;
import so.shanku.essential.adapter.SimpleGridAdater;
import so.shanku.essential.adapter.TopCenterAdapter;
import so.shanku.essential.app.MyApplication;
import so.shanku.essential.getdata.GetDataConfing;
import so.shanku.essential.getdata.GetDataQueue;
import so.shanku.essential.getdata.JsonKeys;
import so.shanku.essential.getdata.ShowGetDataError;
import so.shanku.essential.utils.Constant;
import so.shanku.essential.view.NoTouchLinearLayout;
import striveen.util.used.view.view.gridview.PLA_AdapterView;
import striveen.util.used.view.view.gridview.XGridView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShoppingMallFragment extends BaseFragment {
    /**
     * 筛选点击左边半透明的部分关闭此界面
     */
    @ViewInject(R.id.tv_cancel_left)
    private TextView tv_cancel_left;
    /**
     * 筛选点击左边半透明的部分关闭此界面
     */
    @ViewInject(R.id.tv_cancel_right)
    private TextView tv_cancel_right;
    /**
     * 右侧筛选 分类 当radiogroup中第一个radiobutton为全部时没有分类，（分类字体隐藏）
     */
    @ViewInject(R.id.classify)
    private TextView classify;

    /**
     * horizontalScrollView
     */
    @ViewInject(R.id.horizontalScrollView)
    private HorizontalScrollView horizontalScrollView;

    /**
     * 搜索框的隐藏与显示
     */
    @ViewInject(R.id.linearlayout_search)
    private LinearLayout linearlayout_search;
    /**
     * 搜索商品
     */
    @ViewInject(R.id.search_ed)
    private EditText search_ed;
    @ViewInject(R.id.do_search_iv)
    private ImageView do_search_iv;
    /**
     * 搜索取消
     */
    @ViewInject(R.id.tv_search_cancel)
    private TextView tv_search_cancel;
    /**
     * 搜索图标
     */
    @ViewInject(R.id.iv_search_brand)
    private ImageView iv_search_brand;

    /**
     * 头部框（排序 男士 筛选）的显示与隐藏
     */
    @ViewInject(R.id.relativelayout_top)
    private RelativeLayout relativelayout_top;

    /**
     * 最低价
     */
    @ViewInject(R.id.et_price_from)
    private EditText et_price_from;
    /**
     * 最高价
     */
    @ViewInject(R.id.et_price_to)
    private EditText et_price_to;
    @ViewInject(R.id.lv_top_center_select)
    private ListView lv_top_center_select;
    @ViewInject(R.id.iv_up_or_down)
    private ImageView iv_up_or_down;
    /**
     * 排序控件
     */
    @ViewInject(R.id.tv_order)
    private TextView tv_order; //排序 title
    @ViewInject(R.id.shoppingMall_order_layout)
    private NoTouchLinearLayout shoppingMall_order_layout;
    @ViewInject(R.id.tv_price_low_to_high)
    private TextView tv_price_low_to_high;//价格从低到高

    @ViewInject(R.id.tv_price_high_to_low)
    private TextView tv_price_high_to_low;//价格从高到低

    @ViewInject(R.id.tv_online_newest)
    private TextView tv_online_newest;//最新上线

    @ViewInject(R.id.tv_sell_highest)
    private TextView tv_sell_highest;//销量最高

    /**
     * 筛选布局
     */
    @ViewInject(R.id.tv_select)
    private TextView tv_select; //筛选的title
    /**
     * 筛选linearlayout_search
     */
    @ViewInject(R.id.shoppingMall_rightSide_layout)
    private NoTouchLinearLayout shoppingMall_rightSide_layout;

    @ViewInject(R.id.btn_right_cancel)
    private Button btn_right_cancel;//筛选取消

    @ViewInject(R.id.btn_right_confirm)
    private Button btn_right_confirm;//筛选确定

    @ViewInject(R.id.gridview_classify)
    private GridViewNoScroll gridview_classify; //刷选 分类

    @ViewInject(R.id.gridview_brand)
    private GridViewNoScroll gridview_brand;//

    /**
     * 类别（男士，女士，生活） title
     */
    @ViewInject(R.id.tv_classfiy)
    private TextView tv_classfiy;
    /**
     * 类别（男士，女士，生活） title
     */
    @ViewInject(R.id.linear_top)
    private LinearLayout linear_top;

    /**
     * 全部，sale，服装，鞋履，包装
     */
//    @ViewInject(R.id.rg_shoping)
//    private RadioGroup rg_shoping;

    private int currentLayoutVisibily = -1;//记录当前可见的布局 -1：主布局 0：上布局 1：左侧 2：右侧

    private SimpleGridAdater simpleGridClassifyAdater;
    private SimpleBrandGridAdater simpleGridBrandAdater;
    private TopCenterAdapter topCenterAdapter;
    @ViewInject(R.id.gridview_shoping)
    private XGridView gridview_shoping;
    /**
     * 无相关数据
     */
    @ViewInject(R.id.nodata_layout)
    private LinearLayout nodata_layout;
    private RelationProductAdapter gridAdapter;//XGridView的适配器

    private HashMap<Integer, List<JsonMap<String, Object>>> datas;//存储对应的网络数据，key:导航的序号，value，对应的商品集合
    private List<JsonMap<String, Object>> brandDatas;//排序中品牌的集合
    private List<JsonMap<String, Object>> classfyDatas;//排序中类别的集合
    private List<JsonMap<String, Object>> mainBrandsDatas;//主页导航的集合
    private int pageSize = 10;//每页的个数

    //排序中需要的记录变量
    private int selectClassfy = -1;//刷选中选择的分类
    private int selectBrands = -1;//刷选中选择的品牌
    private String minPrice = "";//刷选中输入的最小的价格
    private String maxPrice = "";  //刷选中输入的最大的价格

    private int currentSelectBrands = 0;//主页选中的item的序列
    private View lastView = null;
    private View lastClassifyView = null;
    private List<JsonMap<String, Object>> data_DownLoadlist;
    private int sort = 0;//左侧排序 初始化是0,1：销量最高2：最新上线3：价格从高到底4：价格从低到高
    private String key = "";   //搜索框中的字
    private String brandId = "";//        //右侧品牌id
    private List<JsonMap<String, Object>> topCenterData;//头部男士女士数据
    private String fatherId = ""; //男士女士id
    private String categoryId = "";//分类id
    private String groupName = ""; //radioButton名称
    /**
     * 头部listview下的view
     */
    @ViewInject(R.id.view_below_lv)
    private View view_below_lv;

    private int oldFlag = 0;
    private int flag = 0;
    @ViewInject(R.id.linearlayout_shoping)
    private LinearLayout linearlayout_shoping;
    @ViewInject(R.id.tv_shopping_radiobutton)
    private TextView addButton;


    private View view_tv;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.shopping_mall_page_layout, container, false);
        initCompont(view);

        shoppingMall_rightSide_layout.setTouchOutSideCancel(true);
        shoppingMall_order_layout.setTouchOutSideCancel(true);
        getData_HeadMan();
        //getData_RgSecondSelect(fatherId);
        gridview_shoping.setXListViewListener(list_loadMoreListener);
        itemClick();
        return view;
    }

    /**
     * 动态添加二级列表 按钮
     */
    public void addRadioButton() {
        horizontalScrollView.setVisibility(View.VISIBLE);
        horizontalScrollView.setSmoothScrollingEnabled(true);

        for (int i = 0; i < mainBrandsDatas.size(); i++) {
            view_tv = getActivity().getLayoutInflater().inflate(R.layout.tv_shopping_radiogroup, null);
            addButton = (TextView) view_tv.findViewById(R.id.tv_shopping_radiobutton);
            addButton.setText(mainBrandsDatas.get(i).getStringNoNull("GroupName"));
            addButton.setTag(i);
            addButton.setOnClickListener(addButtonClick);

            if (mainBrandsDatas.size() <= 5) {
                view_tv.setLayoutParams(new LinearLayout.LayoutParams(MyApplication.getInstance().getScreenWidth() / mainBrandsDatas.size(), LinearLayout.LayoutParams.MATCH_PARENT));
            } else {
                view_tv.setLayoutParams(new LinearLayout.LayoutParams(MyApplication.getInstance().getScreenWidth() / 5, LinearLayout.LayoutParams.MATCH_PARENT));
            }
            linearlayout_shoping.addView(view_tv);
        }
        linearlayout_shoping.getChildAt(0).setSelected(true);

    }

    public int rb_last_checkId = 0;
    /**
     * 添加二级列表按钮的点击事件
     */
    View.OnClickListener addButtonClick = new View.OnClickListener() {


        @Override
        public void onClick(View v) {
            Integer tag = (Integer) v.getTag();
            if (tag != rb_last_checkId) {
                flag = 0;
                linearlayout_shoping.getChildAt(rb_last_checkId).setSelected(false);
                linearlayout_shoping.getChildAt(tag).setSelected(true);
                if (rb_last_checkId < 2 && tag < 3) {

                } else if ((mainBrandsDatas.size() - rb_last_checkId - 1) < 2 && (mainBrandsDatas.size() - tag - 1 < 3)) {

                } else {
                    int x = MyApplication.getInstance().getScreenWidth() / 5 * (tag - rb_last_checkId);
                    horizontalScrollView.smoothScrollTo(x, 0);
                }
                if (tag == 0) {
                    classify.setVisibility(View.GONE);
                } else {
                    classify.setVisibility(View.VISIBLE);
                }
                groupName = mainBrandsDatas.get(tag).getStringNoNull("GroupName");
                getdata_GridView(true);
                getData_RightSelect(groupName);
                getData_RightBrandSelect();
                rb_last_checkId = tag;
            }

        }
    };
    /**
     * Gridview
     */
    XGridView.IXListViewListener list_loadMoreListener = new XGridView.IXListViewListener() {
        @Override
        public void onRefresh() {
            getdata_GridView(true);
        }

        @Override
        public void onLoadMore() {
            getdata_GridView(false);
        }
    };

    public void initCompont(View view) {
        ViewUtils.inject(this, view);
    }


    /**
     * 搜索
     *
     * @param view
     */
    @OnClick(R.id.do_search_iv)
    public void do_search_iv_click(View view) {
        flag = 2;
        searchflag = flag;
        key = search_ed.getText().toString();
        getdata_GridView(true);
    }

    /**
     * 排序按钮的点击
     *
     * @param view
     */
    @OnClick(R.id.tv_order)
    public void tv_order_click(View view) {
        setCurrentLayoutVisibily(1);
    }

    /**
     * 搜索
     *
     * @param view
     */
    private int searchflag;

    @OnClick(R.id.iv_search_brand)
    public void iv_search_brand_click(View view) {
        search_ed.setHint(R.string.search_shopping);
        oldFlag = flag;
        linearlayout_search.setVisibility(View.VISIBLE);
        relativelayout_top.setVisibility(View.GONE);
        horizontalScrollView.setVisibility(View.GONE);
        lv_top_center_select.setVisibility(View.GONE);
        view_below_lv.setVisibility(View.GONE);
        shoppingMall_order_layout.setVisibility(View.GONE);
        shoppingMall_rightSide_layout.setVisibility(View.GONE);
        search_ed.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    flag = 2;
                    searchflag = flag;
                    key = search_ed.getText().toString();
                    getdata_GridView(true);
                    return true;
                }
                return false;
            }
        });

    }

    /**
     * 取消搜索
     */
    @OnClick(R.id.tv_search_cancel)
    private void tv_search_cancel_click(View view) {

        linearlayout_search.setVisibility(View.GONE);
        relativelayout_top.setVisibility(View.VISIBLE);
        horizontalScrollView.setVisibility(View.VISIBLE);
        search_ed.setText("");
        if (searchflag != 0) {
            flag = oldFlag;
            getdata_GridView(true);
        }
        searchflag = 0;
    }

    /**
     * 销量最高
     */
    @OnClick(R.id.tv_sell_highest)
    public void tv_sell_highest_click(View view) {
        flag = 1;
        sort = 1;
        getdata_GridView(true);
        shoppingMall_order_layout.setVisibility(View.GONE);
    }


    /**
     * 最新上线
     */
    @OnClick(R.id.tv_online_newest)
    public void tv_online_newest_click(View view) {
        flag = 1;
        sort = 2;
        getdata_GridView(true);
        shoppingMall_order_layout.setVisibility(View.GONE);
    }

    /**
     * 价格从高到低
     */
    @OnClick(R.id.tv_price_high_to_low)
    public void tv_price_high_to_low_click(View view) {
        flag = 1;
        sort = 3;
        getdata_GridView(true);
        shoppingMall_order_layout.setVisibility(View.GONE);
    }

    /**
     * 价格从低到高
     */
    @OnClick(R.id.tv_price_low_to_high)
    public void tv_price_low_to_high_click(View view) {
        flag = 1;
        sort = 4;
        getdata_GridView(true);
        shoppingMall_order_layout.setVisibility(View.GONE);
    }

    /**
     * 男士女士分类按钮点击事件
     *
     * @param view
     */
    @OnClick(R.id.linear_top)
    public void tv_classfiy_click(View view) {
        //setCurrentLayoutVisibily(0);
    }

    /**
     * 筛选按钮点击事件
     *
     * @param view
     */
    @OnClick(R.id.tv_select)
    public void tv_select_click(View view) {
        setCurrentLayoutVisibily(2);
    }

    /**
     * 筛选确定
     *
     * @param view
     */
    @OnClick(R.id.btn_right_confirm)
    public void btn_right_confirm_click(View view) {
        minPrice = et_price_from.getText().toString();
        maxPrice = et_price_to.getText().toString();
        boolean isClassify = true, isBrand = true;
        if (!(selectClassfy == -1)) {
            categoryId = classfyDatas.get(selectClassfy).getString("id");

        } else {
            categoryId = "";
            isClassify = false;
        }
        if (!(selectBrands == -1)) {
            brandId = brandDatas.get(selectBrands).getString("id");
        } else {
            brandId = "";
            isBrand = false;
        }
        if (isClassify || isBrand || !TextUtils.isEmpty(minPrice) || !TextUtils.isEmpty(maxPrice)) {
            flag = 3;
            getdata_GridView(true);

        } else {
            flag = 0;
            getdata_GridView(true);
        }
        shoppingMall_rightSide_layout.setVisibility(View.GONE);
    }

    /**
     * 筛选取消
     */
    @OnClick(R.id.btn_right_cancel)
    private void btn_right_cancel_click(View view) {
        shoppingMall_rightSide_layout.setVisibility(View.GONE);
    }

    /**
     * 清空右侧筛选数据
     */
    public void clearRightSelect() {
        minPrice = "";
        maxPrice = "";
        et_price_from.setText("");
        et_price_from.setText("");
        lastClassifyView.setSelected(false);
        selectClassfy = -1;
        lastView.setSelected(false);
        selectBrands = -1;
    }

    /**
     * 设置显示的布局 并记录
     *
     * @param type -1：主布局 0：上布局 1：左侧 2：右侧
     */
    private void setCurrentLayoutVisibily(int type) {
        if (currentLayoutVisibily == type) {//相等的话 表示再次点击 则隐藏布局

            if (currentLayoutVisibily == 0) {
                lv_top_center_select.setVisibility(View.GONE);
                view_below_lv.setVisibility(View.GONE);
                iv_up_or_down.setImageResource(R.drawable.pop_down);
            } else if (currentLayoutVisibily == 1) {
                shoppingMall_order_layout.setVisibility(View.GONE);
            } else if (currentLayoutVisibily == 2) {
                shoppingMall_rightSide_layout.setVisibility(View.GONE);
            }
            currentLayoutVisibily = -1;
        } else {
            if (currentLayoutVisibily == 0) {
                lv_top_center_select.setVisibility(View.GONE);
                view_below_lv.setVisibility(View.GONE);
                iv_up_or_down.setImageResource(R.drawable.pop_down);
            } else if (currentLayoutVisibily == 1) {
                shoppingMall_order_layout.setVisibility(View.GONE);
            } else if (currentLayoutVisibily == 2) {
                shoppingMall_rightSide_layout.setVisibility(View.GONE);
            }

            if (type == 0) {
                lv_top_center_select.setVisibility(View.VISIBLE);
                view_below_lv.setVisibility(View.VISIBLE);
                iv_up_or_down.setImageResource(R.drawable.pop_up);
            } else if (type == 1) {
                shoppingMall_order_layout.setVisibility(View.VISIBLE);
            } else if (type == 2) {
                shoppingMall_rightSide_layout.setVisibility(View.VISIBLE);
            }
            currentLayoutVisibily = type;
        }
    }

    public void itemClick() {

        gridview_classify.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (selectClassfy == position) {
                    lastClassifyView.setSelected(false);
                    selectClassfy = -1;
                } else {
                    if (lastClassifyView != null) {
                        lastClassifyView.setSelected(false);
                    }
                    view.setSelected(true);
                    selectClassfy = position;
                    lastClassifyView = view;
                }

            }
        });
        gridview_brand.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (selectBrands == position) {
                    lastView.setSelected(false);
                    selectBrands = -1;
                } else {
                    if (lastView != null) {
                        lastView.setSelected(false);
                    }
                    view.setSelected(true);
                    selectBrands = position;
                    lastView = view;
                }
            }
        });
        gridview_shoping.setOnItemClickListener(new PLA_AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(PLA_AdapterView<?> parent, View view, int position, long id) {
                if (position > 0) {
                    String productId = data_DownLoadlist.get(position - 1).getStringNoNull("ProductId");
                    activity.seeProductDetail(productId);
                }
            }
        });
        /**
         * 头部男士女士listview的点击
         */
        lv_top_center_select.setOnItemClickListener(new AdapterView.OnItemClickListener() {


            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                rb_last_checkId = 0;
                flag = 0;
                linearlayout_shoping.removeAllViews();
                topCenterAdapter.setSelectIndex(position);
                topCenterAdapter.notifyDataSetChanged();
                lv_top_center_select.setVisibility(View.GONE);
                view_below_lv.setVisibility(View.GONE);
                fatherId = topCenterData.get(position).getStringNoNull("id");
                getData_RgSecondSelect(fatherId);
                iv_up_or_down.setImageResource(R.drawable.pop_down);
                tv_classfiy.setText(topCenterData.get(position).getStringNoNull("name"));

            }
        });
    }

    /**
     * 一级列表（获取头部男士女士生活筛选）
     */
    private void getData_HeadMan() {
        loadingToast.show();
        GetDataQueue queue = new GetDataQueue();
        queue.setActionName(GetDataConfing.GetAction_SelectProudctCategroyList);
        queue.setCallBack(callBack);
        queue.setParams(null);
        queue.setWhat(GetDataConfing.what_SelectProudctCategroyList);
        getDataUtil.getData(queue);
    }

    /**
     * 二级类表（RadioGroup数据）
     */
    private void getData_RgSecondSelect(String id) {
        loadingToast.show();
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(GetDataQueue.Params_key, GetDataConfing.Key_Str);
        params.put("Id", id);
        GetDataQueue queue = new GetDataQueue();
        queue.setActionName(GetDataConfing.GetAction_SelectSecondCategroyList);
        queue.setCallBack(callBack);
        queue.setParamsNoJson(params);
        queue.setWhat(GetDataConfing.what_SelectSecondCategroyList);
        getDataUtil.getData(queue);
    }

    /**
     * 三级列表（品牌）
     */
    private void getData_RightBrandSelect() {
        loadingToast.show();
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(GetDataQueue.Params_key, GetDataConfing.Key_Str);
        params.put("CategroyId", fatherId);
        params.put("GroupName", groupName);
        GetDataQueue queue = new GetDataQueue();
        queue.setActionName(GetDataConfing.GetAction_ShopingSelectBrandList);
        queue.setCallBack(callBack);
        queue.setParamsNoJson(params);
        queue.setWhat(GetDataConfing.what_ShopingSelectBrandList);
        getDataUtil.getData(queue);
    }

    /**
     * 三级列表(分类)
     */
    private void getData_RightSelect(String groupName) {
        loadingToast.show();
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(GetDataQueue.Params_key, GetDataConfing.Key_Str);
        params.put("GroupName", groupName);
        params.put("fatherId", fatherId);
        GetDataQueue queue = new GetDataQueue();
        queue.setActionName(GetDataConfing.GetAction_SelectTheThirdCategroyList);
        queue.setCallBack(callBack);
        queue.setParamsNoJson(params);
        queue.setWhat(GetDataConfing.what_SelectTheThirdCategroyList);
        getDataUtil.getData(queue);
    }

    /**
     * 获取网络数据  搜索产品的接口
     */
    private int page = 0, ismore = 0;

    private void getdata_GridView(boolean chearAllData) {
        loadingToast.show();
        if (chearAllData) {
            if (data_DownLoadlist != null && !data_DownLoadlist.isEmpty()) {
                data_DownLoadlist.clear();
            }
            if (gridAdapter != null) {
                gridAdapter.setDatas(data_DownLoadlist);
                gridAdapter.notifyDataSetChanged();
            }
            ismore = 0;
            page = 0;
            gridview_shoping.setPullRefreshEnable(true);
            gridview_shoping.setPullLoadEnable(true);
        }


        Map<String, Object> params = new HashMap<String, Object>();
        params.put(GetDataQueue.Params_key, GetDataConfing.Key_Str);
        if (flag == 0) {    //最大权限筛选
            params.put("Sort", 0);
            params.put("currentPage", page + 1);
            params.put("pageSize", pageSize);
            params.put("Key", "");
            params.put("Statprice", "");
            params.put("Endprice", "");
            params.put("brandId", "");
            params.put("fatherId", fatherId);
            params.put("GroupName", groupName);
            params.put("categoryId", "");
        } else if (flag == 1) {     //左侧排序筛选
            params.put("Sort", sort);
            params.put("currentPage", page + 1);
            params.put("pageSize", pageSize);
            params.put("Key", "");
            params.put("Statprice", "");
            params.put("Endprice", "");
            params.put("brandId", "");
            params.put("fatherId", fatherId);
            params.put("GroupName", groupName);
            params.put("categoryId", "");
        } else if (flag == 2) {//搜索筛选
            params.put("Sort", 0);
            params.put("currentPage", page + 1);
            params.put("pageSize", pageSize);
            params.put("Key", key);
            params.put("Statprice", "");
            params.put("Endprice", "");
            params.put("brandId", "");
            params.put("fatherId", "");
            params.put("GroupName", "");
            params.put("categoryId", "");
        } else if (flag == 3) {      //右侧筛选
            params.put("Sort", 0);
            params.put("currentPage", page + 1);
            params.put("pageSize", pageSize);
            params.put("Key", "");
            params.put("Statprice", minPrice);
            params.put("Endprice", maxPrice);
            params.put("brandId", brandId);
            params.put("fatherId", fatherId);
            params.put("GroupName", groupName);
            params.put("categoryId", categoryId);
        }

        GetDataQueue queue = new GetDataQueue();
        queue.setCallBack(callBack);
        queue.setActionName(GetDataConfing.GetAction_SelectsearchProductList);
        queue.setWhat(GetDataConfing.what_SelectsearchProductList);
        queue.setParamsNoJson(params);
        getDataUtil.getData(queue);
    }

    private void setAdatper_singleSortlist(final List<JsonMap<String, Object>> data) {

        if (data.size() == 0 || data.size() % pageSize != 0) {
            ismore = 1;//加载完毕
            gridview_shoping.setPullLoadEnable(false);
//			if (page == 0 && data.size() > 0 || page != 0)
//				toast.showToast(R.string.xlistview_no_more_data);

        }
        if (page == 0) {
            this.data_DownLoadlist = data;
            gridAdapter = new RelationProductAdapter(getActivity());
            gridAdapter.setDatas(data);
            gridAdapter.setShowDiscri(true);
            gridview_shoping.setAdapter(gridAdapter);
        } else {
            this.data_DownLoadlist.addAll(data);
            gridAdapter.notifyDataSetChanged();
        }
        page++;

    }

    /**
     * 获取服务器数据的返回信息
     */
    private GetServicesDataUtil.IGetServicesDataCallBack callBack = new GetServicesDataUtil.IGetServicesDataCallBack() {
        @Override
        public void onLoaded(GetServicesDataQueue entity) {
            if (entity.isOk()) {
                if (ShowGetDataError.isOkAndCodeIsNot1(getActivity(),
                        entity.getInfo())) {
                    List<JsonMap<String, Object>> data = JsonParseHelper.getJsonMap_List_JsonMap(
                            entity.getInfo(), JsonKeys.Key_Info);
                    if (entity.what == GetDataConfing.what_SelectProudctCategroyList) {   //头部中间男士女士筛选
                        topCenterData = data;
                        //String firstName = data.get(0).getStringNoNull("name");
                        fatherId = data.get(0).getStringNoNull("id");
                        //tv_classfiy.setText(firstName);
                        //topCenterAdapter = new TopCenterAdapter(getActivity(), data);
                        //lv_top_center_select.setAdapter(topCenterAdapter);
                        getData_RgSecondSelect(fatherId);
                    } else if (entity.what == GetDataConfing.what_SelectTheThirdCategroyList) {   //筛选分类
                        classfyDatas = data;
                        simpleGridClassifyAdater = new SimpleGridAdater(getActivity(), data);
                        gridview_classify.setAdapter(simpleGridClassifyAdater);
                    } else if (entity.what == GetDataConfing.what_ShopingSelectBrandList) {       //筛选品牌列表
                        brandDatas = data;
                        simpleGridBrandAdater = new SimpleBrandGridAdater(getActivity(), data);
                        gridview_brand.setAdapter(simpleGridBrandAdater);

                    } else if (entity.what == GetDataConfing.what_SelectsearchProductList) { //主数据
                        setAdatper_singleSortlist(data);
                        invalidateListData();
                    } else if (entity.what == GetDataConfing.what_SelectSecondCategroyList) {  //二级列表（radiogroup）
                        mainBrandsDatas = data;
                        addRadioButton();
                        groupName = mainBrandsDatas.get(0).getStringNoNull("GroupName");
                        getData_RightSelect(groupName);
                        classify.setVisibility(View.GONE);
                        getData_RightBrandSelect();
                        getdata_GridView(true);
                    }
                }
            } else {
                ShowGetDataError.showNetError(getActivity());
            }
            loadingToast.dismiss();
            gridview_shoping.stopLoadMore();
            gridview_shoping.stopRefresh();
            invalidateListData();
        }
    };

    private void invalidateListData() {
        if (data_DownLoadlist == null || data_DownLoadlist.size() < 1) {
            gridview_shoping.setVisibility(View.GONE);
            nodata_layout.setVisibility(View.VISIBLE);
        } else {
            gridview_shoping.setVisibility(View.VISIBLE);
            nodata_layout.setVisibility(View.GONE);
        }
    }

    /**
     * 排序点击右边半透明的部分关闭此界面
     */
    @OnClick(R.id.tv_cancel_right)
    public void tv_cancel_right_click(View view) {
        shoppingMall_order_layout.setVisibility(View.GONE);
    }

    /**
     * 筛选点击左边半透明的部分关闭此界面
     */
    @OnClick(R.id.tv_cancel_left)
    public void tv_cancel_left_click(View view) {
        shoppingMall_rightSide_layout.setVisibility(View.GONE);
    }
}
